package com.yx.cloud.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.yx.cloud.R;
import com.yx.cloud.activity.MusicAlbumDetailActivity;
import com.yx.cloud.product.sdk.tmall.MusicInfo;
import com.yx.cloud.utils.RomUtils;
import com.yx.cloud.view.CarouselViewPager;
import com.yx.cloud.view.SubCateRecyclerView;
import com.iot.common.utils.LogUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MusicAlbumListAdapter extends RecyclerView.Adapter implements View.OnClickListener{
    private static final String TAG = "MusicAlbumListAdapter";
    private Context context;
    private List<MusicInfo> mMusicInfoList;
    private List<MusicInfo> mSubCateList;
    private InnerItemOnclickListener listener;
    private int currentPos = -1;
    private int musicPlaying = -1;
    private boolean changePlayBtnShow = false;
    private Set<String> iconUriSet;
    private RequestOptions options;
    private long cateId;
    //图片（广告）
    public static final int ITEM_IMAGE_ADVERTISEMENT = 0;
    //图片（轮播）
    public static final int ITEM_IMAGE_CAROUSEL = 1;
    //二级类目分类
    public static final int ITEM_SUB_CATE = 2;
    //类目内容
    public static final int ITEM_CONTENT = 3;
    //其他系列
    public static final int ITEM_OTHER = 4;

    public MusicAlbumListAdapter(Context context, List<MusicInfo> musicInfoList,long cateId) {
        this.context = context;
        this.iconUriSet = new HashSet<>();
        this.mMusicInfoList = musicInfoList;
        this.cateId = cateId;
        this.options = new RequestOptions()
                .bitmapTransform(new RoundedCorners(30));
        this.mSubCateList = new ArrayList<>();
    }

    public void  updateData(List<MusicInfo> musicInfoList){
        this.mMusicInfoList = musicInfoList;
        notifyDataSetChanged();
    }

    public void  selectItem(int position){
        currentPos = position;
        notifyDataSetChanged();
    }

    public MusicInfo getItem(int position){
        return mMusicInfoList.get(position);
    }

    public int getSelectedItem(){
        return currentPos;
    }

    @Override
    public int getItemCount() {
        return mMusicInfoList.size();
    }


    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        changePlayBtnShow = true;
        currentPos = (int)v.getTag();
        listener.itemClick(v,(int)v.getTag());
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if(viewType == ITEM_IMAGE_ADVERTISEMENT) {
            return new ImageAdvertisementViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.image_advertisement, parent, false));
        }else if(viewType == ITEM_IMAGE_CAROUSEL){
            return new ImageCarouselViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.image_carousel_item, parent, false));
        }else if(viewType == ITEM_CONTENT){
            return new ContentViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.muscicatelist_item, parent, false));
        }else if(viewType == ITEM_SUB_CATE) {
            return new SubCateViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.sub_cate_list, parent, false));
        }else {
            return null;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ContentViewHolder){
            MusicInfo musicInfo = mMusicInfoList.get(position);
            ContentViewHolder myViewHolder = (ContentViewHolder) holder;
            myViewHolder.rlAlbumCover.setOnClickListener(this);
            myViewHolder.rlAlbumCover.setTag(position);

            if(currentPos == position){
                if(changePlayBtnShow){
                    changePlayBtnShow(myViewHolder,musicInfo);
                    changePlayBtnShow = false;
                }else {
                    refreshPlayBtnShow(myViewHolder,musicInfo);
                }
            }else {
                // myViewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
                musicInfo.setMusicPlayStatus(MusicInfo.STATE_IDLE);
                //myViewHolder.progressBarView.setProgress(0);
            }

            String icon = musicInfo.getCoverUrl();
            if(icon == null || icon.equals("")){
                if(musicInfo.getCoverDrawableId() != -1){
                    Glide.with(context).load(musicInfo.getCoverDrawableId()).placeholder(R.mipmap.music_cover_default).apply(options).into(myViewHolder.ivMusicIcon);
                }else {
                    myViewHolder.ivMusicIcon.setImageResource(R.mipmap.music_cover_default);
                }
            }else {
                Glide.with(context).load(icon).placeholder(R.mipmap.music_cover_default).apply(options).into(myViewHolder.ivMusicIcon);
            }
            myViewHolder.tvMusicName.setText(musicInfo.getTitle());
            myViewHolder.tvSinger.setText(musicInfo.getSingers());
            Log.d("music","play position + " + position);
        }else if(holder instanceof ImageCarouselViewHolder){
            // do nothing
        }
    }

    @Override
    public int getItemViewType(int position)
    {
        if(cateId == 10000L){
            if (position == 0) {
                //第一个是图片广告
                //return ITEM_IMAGE_ADVERTISEMENT;
                return ITEM_CONTENT;
            } else if (position == 1) {
                //第三个是子类分类
                //return ITEM_SUB_CATE;
                return ITEM_CONTENT;
            } else if (position == 3) {
                //第四个分类内容
                return ITEM_CONTENT;
            }
        }else {
           if (position == 0) {
                //第三个是子类分类
                return ITEM_SUB_CATE;
            } else {
                //第四个分类内容
                return ITEM_CONTENT;
            }
        }
        //其他
        return ITEM_CONTENT;
    }

    //一个item布局占网格的多少份
    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager) {
            GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
            gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    if (ITEM_IMAGE_ADVERTISEMENT == getItemViewType(position) || ITEM_IMAGE_CAROUSEL == getItemViewType(position) || ITEM_SUB_CATE == getItemViewType(position)) {
                        return 3;
                    } else if(ITEM_CONTENT == getItemViewType(position)){
                        return 1 ;
                    }else if (ITEM_OTHER == getItemViewType(position)) {
                        return 1;
                    }
                    return 1;
                }
            });
        }
    }

    private void changePlayBtnShow(MusicAlbumListAdapter.ContentViewHolder viewHolder,MusicInfo musicInfo){
        if(musicInfo.getMusicPlayStatus() == MusicInfo.STATE_PAUSE){
            Log.d("music","set music playing");
            musicInfo.setMusicPlayStatus(MusicInfo.STATE_PLAY);
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_playing);
            //viewHolder.progressBarView.setProgress(musicInfo.getProgress());
            musicPlaying = 1;
            //播放完毕
            if(musicInfo.getProgress() == 100){
               // viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
                musicInfo.setMusicPlayStatus(MusicInfo.STATE_IDLE);
                //viewHolder.progressBarView.setProgress(0);
                musicPlaying = -1;
            }
        }else if(musicInfo.getMusicPlayStatus().equals(MusicInfo.STATE_PLAY)){
            Log.d("music","set music stop");
            musicInfo.setMusicPlayStatus(MusicInfo.STATE_PAUSE);
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
           // viewHolder.progressBarView.setProgress(0);
            musicPlaying = 0;
        }else if(musicInfo.getMusicPlayStatus().equals(MusicInfo.STATE_IDLE)){
            Log.d("music","set music playing");
            musicInfo.setMusicPlayStatus(MusicInfo.STATE_PLAY);
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_playing);
            //viewHolder.progressBarView.setProgress(musicInfo.getProgress());
            musicPlaying = 1;
        }
    }

    private void refreshPlayBtnShow(MusicAlbumListAdapter.ContentViewHolder viewHolder,MusicInfo musicInfo){
        if(musicInfo.getMusicPlayStatus().equals(MusicInfo.STATE_PAUSE)){
            Log.d("music","set music stop");
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
            //viewHolder.progressBarView.setProgress(0);
            musicPlaying = 0;
        }else if(musicInfo.getMusicPlayStatus().equals(MusicInfo.STATE_PLAY)){
            Log.d("music","set music playing");
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_playing);
            //viewHolder.progressBarView.setProgress(musicInfo.getProgress());
            musicPlaying = 1;
            //播放完毕
            if(musicInfo.getProgress() == 100){
                //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
                musicInfo.setMusicPlayStatus(MusicInfo.STATE_IDLE);
               // viewHolder.progressBarView.setProgress(0);
                musicPlaying = -1;
            }
        }else {
            Log.d("music","reset music");
            //viewHolder.ivMusicPlay.setBackgroundResource(R.mipmap.music_stop);
            //viewHolder.progressBarView.setProgress(0);
            musicPlaying = -1;
        }
    }

    public void updateMusic(List<MusicInfo> musicInfoList) {
        mMusicInfoList = musicInfoList;
        //加载数据

        if(cateId != 10000L){
            MusicInfo imageCarouse = new MusicInfo();
            mMusicInfoList.add(0,imageCarouse);
        }
         if(cateId == 80021L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }
            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_PopMusic));
            subCate1.setRawId("MC201136");
            subCate1.setCoverDrawableId(R.mipmap.subcate_pop_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setRawId("白噪音");
            subCate2.setTitle(context.getString(R.string.M_Relaxed));
            subCate2.setCoverDrawableId(R.mipmap.subcate_relax_naturally_music_cover);
            mSubCateList.add(subCate2);
            MusicInfo subCate3 = new MusicInfo();
            subCate3.setRawId("MC201133");
            subCate3.setTitle(context.getString(R.string.M_Ballad));
            subCate3.setCoverDrawableId(R.mipmap.subcate_ballad_music_cover);
            mSubCateList.add(subCate3);
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setRawId("MC201132");
            subCate4.setTitle(context.getString(R.string.M_ChineseStyle));
            subCate4.setCoverDrawableId(R.mipmap.subcate_chinese_ballad_music_cover);
            mSubCateList.add(subCate4);
            MusicInfo subCate5 = new MusicInfo();
            subCate5.setRawId("MC201139");
            subCate5.setTitle(context.getString(R.string.M_Love));
            subCate5.setCoverDrawableId(R.mipmap.subcate_love_music_cover);
            mSubCateList.add(subCate5);
        }else if(cateId == 80011L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }
            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_NurseryRhymes));
            subCate1.setRawId("80011001");
            subCate1.setCoverDrawableId(R.mipmap.subcate_nursery_rhyme_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setTitle(context.getString(R.string.M_NurseryRhymes_En));
            subCate2.setRawId("80011009");
            subCate2.setCoverDrawableId(R.mipmap.subcate_english_nursery_rhyme_music_cover);
            mSubCateList.add(subCate2);
            MusicInfo subCate3 = new MusicInfo();
            subCate3.setTitle(context.getString(R.string.M_Poetry));
            subCate3.setRawId("80011015");
            subCate3.setCoverDrawableId(R.mipmap.subcate_poetry_music_cover);
            mSubCateList.add(subCate3);
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setTitle(context.getString(R.string.M_Encyclopedia));
            subCate4.setRawId("80011005");
            subCate4.setCoverDrawableId(R.mipmap.subcate_wiki_music_cover);
            mSubCateList.add(subCate4);
            MusicInfo subCate5 = new MusicInfo();
            subCate5.setTitle(context.getString(R.string.M_Story));
            subCate5.setRawId("80011004");
            subCate5.setCoverDrawableId(R.mipmap.subcate_story_music_cover);
            mSubCateList.add(subCate5);
        }else if(cateId == 80050L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }

            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_BestSeller));
            subCate1.setRawId("80073");
            subCate1.setCoverDrawableId(R.mipmap.subcate_bestseller_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setTitle(context.getString(R.string.M_Growing));
            subCate2.setRawId("80060");
            subCate2.setCoverDrawableId(R.mipmap.subcate_growth_training_music_cover);
            mSubCateList.add(subCate2);
            MusicInfo subCate3 = new MusicInfo();
            subCate3.setTitle(context.getString(R.string.M_History));
            subCate3.setRawId("80011003");
             subCate3.setCoverDrawableId(R.mipmap.subcate_history_music_cover);
            mSubCateList.add(subCate3);
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setTitle(context.getString(R.string.M_Read));
            subCate4.setRawId("MC201137");
             subCate4.setCoverDrawableId(R.mipmap.subcate_relax_reading_music_cover);
            mSubCateList.add(subCate4);
            MusicInfo subCate5 = new MusicInfo();
            subCate5.setTitle(context.getString(R.string.M_Educate));
            subCate5.setRawId("80014");
             subCate5.setCoverDrawableId(R.mipmap.subcate_education_training_music_cover);
            mSubCateList.add(subCate5);
        }else if(cateId == 80010L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }

            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_Hot));
            subCate1.setRawId("80051001");
             subCate1.setCoverDrawableId(R.mipmap.subcate_hotspot_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setTitle(context.getString(R.string.M_International));
            subCate2.setRawId("80051002");
             subCate2.setCoverDrawableId(R.mipmap.subcate_international_music_cover);
            mSubCateList.add(subCate2);
            MusicInfo subCate3 = new MusicInfo();
            subCate3.setTitle(context.getString(R.string.M_Society));
            subCate3.setRawId("80051003");
             subCate3.setCoverDrawableId(R.mipmap.subcate_society_music_cover);
            mSubCateList.add(subCate3);
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setTitle(context.getString(R.string.M_Financial));
            subCate4.setRawId("80058");
             subCate4.setCoverDrawableId(R.mipmap.subcate_finance_music_cover);
            mSubCateList.add(subCate4);
            MusicInfo subCate5 = new MusicInfo();
            subCate5.setTitle(context.getString(R.string.M_Recreation));
             subCate5.setCoverDrawableId(R.mipmap.subcate_entertainment_music_cover);
            subCate5.setRawId("80051005");
            mSubCateList.add(subCate5);
        } else if(cateId == 80035L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }
            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_City));
            subCate1.setRawId("80035");
             subCate1.setCoverDrawableId(R.mipmap.subcate_urban_fantasy_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setTitle(context.getString(R.string.M_PureLove));
            subCate2.setRawId("80037");
            subCate2.setCoverDrawableId(R.mipmap.subcate_pure_love_music_cover);
            mSubCateList.add(subCate2);
            MusicInfo subCate3 = new MusicInfo();
            subCate3.setTitle(context.getString(R.string.M_Suspend));
            subCate3.setRawId("80036");
             subCate3.setCoverDrawableId(R.mipmap.subcate_suspensive_reasoning_music_cover);
            mSubCateList.add(subCate3);
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setTitle(context.getString(R.string.M_MartialArts));
            subCate4.setRawId("80039");
             subCate4.setCoverDrawableId(R.mipmap.subcate_knight_errant_music_cover);
            mSubCateList.add(subCate4);
            MusicInfo subCate5 = new MusicInfo();
            subCate5.setTitle(context.getString(R.string.M_Literature));
            subCate5.setRawId("80071");
             subCate5.setCoverDrawableId(R.mipmap.subcate_historical_literature_music_cover);
            mSubCateList.add(subCate5);
            MusicInfo subCate6 = new MusicInfo();
            subCate6.setTitle(context.getString(R.string.M_Military));
            subCate6.setRawId("80070");
             subCate6.setCoverDrawableId(R.mipmap.subcate_military_war_music_cover);
            mSubCateList.add(subCate6);
            MusicInfo subCate7 = new MusicInfo();
            subCate7.setTitle(context.getString(R.string.M_Romance));
            subCate7.setRawId("80038");
             subCate7.setCoverDrawableId(R.mipmap.subcate_romance_music_cover);
            mSubCateList.add(subCate7);
        }else if(cateId == 80054L){
            if(mSubCateList != null){
                mSubCateList.clear();
            }

            MusicInfo subCate1 = new MusicInfo();
            subCate1.setTitle(context.getString(R.string.M_Sinology));
            subCate1.setRawId("80054001");
             subCate1.setCoverDrawableId(R.mipmap.subcate_ancient_chinese_iterature_search_music_cover);
            mSubCateList.add(subCate1);
            MusicInfo subCate2 = new MusicInfo();
            subCate2.setTitle(context.getString(R.string.M_Masterpiece));
            subCate2.setRawId("80054003");
             subCate2.setCoverDrawableId(R.mipmap.subcate_literary_masterpieces_music_cover);
            mSubCateList.add(subCate2);
            /*MusicInfo subCate3 = new MusicInfo();
            subCate3.setTitle("名人传");
            subCate3.setRawId("80054009");
            mSubCateList.add(subCate3);*/
            MusicInfo subCate4 = new MusicInfo();
            subCate4.setTitle(context.getString(R.string.M_HundredForums));
            subCate4.setRawId("80054011");
             subCate4.setCoverDrawableId(R.mipmap.subcate_one_hundred_forums_music_cover);
            mSubCateList.add(subCate4);
            /*MusicInfo subCate5 = new MusicInfo();
            subCate5.setTitle("读书会");
            subCate5.setRawId("80054012");
            mSubCateList.add(subCate5);*/
            MusicInfo subCate6 = new MusicInfo();
            subCate6.setTitle(context.getString(R.string.M_Crosstalk_G));
            subCate6.setRawId("80052005");
             subCate6.setCoverDrawableId(R.mipmap.subcate_guodegan_music_cover);
            mSubCateList.add(subCate6);
            MusicInfo subCate7 = new MusicInfo();
            subCate7.setTitle(context.getString(R.string.M_Crosstalk_Y));
            subCate7.setRawId("80052006");
             subCate7.setCoverDrawableId(R.mipmap.subcate_yueyunpeng_music_cover);
            mSubCateList.add(subCate7);
            MusicInfo subCate8 = new MusicInfo();
            subCate8.setTitle(context.getString(R.string.M_Crosstalk_S));
            subCate8.setRawId("80052007");
             subCate8.setCoverDrawableId(R.mipmap.subcate_shangtianfang_music_cover);
            mSubCateList.add(subCate8);
        }
        loadCover(musicInfoList);
        notifyDataSetChanged();
    }

    public void addMusic(List<MusicInfo> musicInfoList) {
        if(musicInfoList == null){
            return;
        }
        mMusicInfoList.addAll(musicInfoList);
        notifyDataSetChanged();
        loadCover(musicInfoList);
    }

    private void loadCover(List<MusicInfo> musicInfoList){
        iconUriSet.clear();
        LogUtils.i("load image uri size : " + iconUriSet.size());
        for (int i = 0; i < musicInfoList.size(); i++) {
            if(musicInfoList.get(i).getCoverUrl() != null){
                iconUriSet.add(musicInfoList.get(i).getCoverUrl());
            }
        }
        LogUtils.i("load image uri size1 : " + iconUriSet.size());
    }

    public List<MusicInfo> getmMusicInfoList() {
        return mMusicInfoList;
    }

    public void setmMusicInfoList(List<MusicInfo> mMusicInfoList) {
        this.mMusicInfoList = mMusicInfoList;
    }


    public int getMusicPlaying() {
        return musicPlaying;
    }

    public void setMusicPlaying(int musicPlaying) {
        this.musicPlaying = musicPlaying;
    }

    public boolean isChangePlayBtnShow() {
        return changePlayBtnShow;
    }

    public void setChangePlayBtnShow(boolean changePlayBtnShow) {
        this.changePlayBtnShow = changePlayBtnShow;
    }

    public interface InnerItemOnclickListener {
        void itemClick(View v,int position);
    }

    public void setOnInnerItemOnClickListener(InnerItemOnclickListener listener) {
        this.listener = listener;
    }

    class ContentViewHolder extends  RecyclerView.ViewHolder{
        RelativeLayout rlAlbumCover;
        ImageView ivMusicIcon;
        TextView tvMusicName;
        TextView tvSinger;
        public ContentViewHolder(View itemView) {
            super(itemView);
            rlAlbumCover = itemView.findViewById(R.id.rl_album_cover);
            ivMusicIcon = itemView.findViewById(R.id.iv_music_item_icon);
            tvMusicName = itemView.findViewById(R.id.tv_music_name);
            tvSinger = itemView.findViewById(R.id.tv_singer);
        }
    }

    class SubCateViewHolder extends  RecyclerView.ViewHolder implements SubCateViewAdapter.InnerItemOnclickListener{
        SubCateViewAdapter adapter;
        SubCateRecyclerView recyclerView;
        List<MusicInfo> musicInfoList;
        public SubCateViewHolder(View itemView) {
            super(itemView);
            recyclerView = itemView.findViewById(R.id.rv_sub_cate_recycler);
            recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
            musicInfoList = mSubCateList;
            adapter = new SubCateViewAdapter(context, musicInfoList,cateId);
            adapter.setOnInnerItemOnClickListener(this);
            recyclerView.setAdapter(adapter);
        }

        @Override
        public void itemClick(View v, int position) {
            Log.d("music","itemClick");
            if(mSubCateList != null && mSubCateList.size() > 0){
                MusicInfo musicInfo = mSubCateList.get(position);
                new Thread(() -> {
                    Intent intent = new Intent(context, MusicAlbumDetailActivity.class);
                    intent.putExtra("musicInfo", new Gson().toJson(musicInfo));
                    context.startActivity(intent);
                    Activity activity = (Activity) context;
                    activity.overridePendingTransition(R.anim.in_from_right,
                            R.anim.out_to_left);
                }).start();
            }
        }

    }

    /**
     * 广告图
     * */
    class ImageAdvertisementViewHolder extends  RecyclerView.ViewHolder{

        ImageView ivAdvertisement;
        public ImageAdvertisementViewHolder(View itemView) {
            super(itemView);
            ivAdvertisement = itemView.findViewById(R.id.image_advertisement);
            ivAdvertisement.setBackgroundResource(R.mipmap.recommend_cover);
        }
    }

    /**
     * 轮播图
     */
    public class ImageCarouselViewHolder extends RecyclerView.ViewHolder {
        private CarouselViewPager mViewPager;
        //容器
        private List<View> mList = new ArrayList<>();
        private View imageCarouse1, imageCarouse2, imageCarouse3, imageCarouse4;
        //小圆点
        private ImageView point1, point2, point3, point4;
        public ImageCarouselViewHolder(View itemView) {
            super(itemView);
            point1 = itemView.findViewById(R.id.recommend_point1);
            point2 = itemView.findViewById(R.id.recommend_point2);
            point3 = itemView.findViewById(R.id.recommend_point3);
            point4 = itemView.findViewById(R.id.recommend_point4);

            //设置默认图片
            setPointImg(true, false, false, false);
            mViewPager = itemView.findViewById(R.id.vp_recommend);

            imageCarouse1  = View.inflate(context, R.layout.image_carousel, null);
//            imageCarouse1.setBackgroundResource(R.mipmap.recommend_cover);
            imageCarouse2 = View.inflate(context, R.layout.image_carousel, null);
            imageCarouse2.setBackgroundResource(R.mipmap.music_cover_default);
            imageCarouse3 = View.inflate(context, R.layout.image_carousel, null);
            imageCarouse3.setBackgroundResource(R.mipmap.music_album_background);
            imageCarouse4 = View.inflate(context, R.layout.image_carousel, null);
            imageCarouse4.setBackgroundResource(R.mipmap.music_stop);

            mList.add(imageCarouse1);
            mList.add(imageCarouse2);
            mList.add(imageCarouse3);
            mList.add(imageCarouse4);

            //设置适配器
            mViewPager.setAdapter(new ImageCarouselViewHolder.RecommendAdapter());

            //监听ViewPager滑动
            mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                }

                //pager切换
                @SuppressLint("ResourceAsColor")
                @Override
                public void onPageSelected(int position) {
                    switch (position) {
                        case 0:
                            setPointImg(true, false, false, false);
                            break;
                        case 1:
                            setPointImg(false, true, false, false);
                            break;
                        case 2:
                            setPointImg(false, false, true, false);
                            break;
                        case 3:
                            setPointImg(false, false, false, true);
                            break;
                    }
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                }
            });
        }

        // 设置小圆点的选中效果
        private void setPointImg(boolean isCheck1, boolean isCheck2, boolean isCheck3, boolean isCheck4) {
            if (isCheck1) {
                point1.setBackgroundResource(R.drawable.guide_dot_pitch);
            } else {
                point1.setBackgroundResource(R.drawable.guide_dot_default);
            }

            if (isCheck2) {
                point2.setBackgroundResource(R.drawable.guide_dot_pitch);
            } else {
                point2.setBackgroundResource(R.drawable.guide_dot_default);
            }

            if (isCheck3) {
                point3.setBackgroundResource(R.drawable.guide_dot_pitch);
            } else {
                point3.setBackgroundResource(R.drawable.guide_dot_default);
            }

            if (isCheck4) {
                point4.setBackgroundResource(R.drawable.guide_dot_pitch);
            } else {
                point4.setBackgroundResource(R.drawable.guide_dot_default);
            }
        }

        class RecommendAdapter extends PagerAdapter {

            @Override
            public int getCount() {
                return mList.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(mList.get(position));
                return mList.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(mList.get(position));
            }
        }

    }
}
